count = 0
gold = 5000
print('猜数字')
print('你共有金币%d' % gold)
flag = 1
while gold > 0 and flag == 1:
         import random
         ran = random.randint(1, 50)
         while True:
             guess = int(input('请输入数字：'))
             count = count + 1
             if guess == ran:
                 gold = gold + 3000
                 print('猜对了，奖励3000金币，你还剩金币%d' % gold)
                 print('您是否继续游戏，继续请输入1，不继续请输入除1以外任何数字')
                 cont = int(input('请选择：'))
                 if cont == 1:
                     flag = 1
                 else:
                     flag = 0
                 break
             elif guess > ran:
                 gold = gold - 500
                 print('大了，扣除500金币，你还剩金币%d' % gold)
             else:
                 gold = gold - 500
                 print('小了, 扣除500金币，你还剩金币%d' % gold)

print('你一共猜了%d'% count)
